<?php
/*
* LoginModel.php
* Contains functions to execute on the database and login the user.
*/
class LoginModel
{
	/**
	* LoginUser
	* Authenticate/login the user.
	*
	* @param string $username The username to login.
	* @param string $password The matching password (to the username).
	*
	* @return bool True if the username and password match in the database.
	*			False is the username and password don't match in the database
				or if the user doesn't exist.
	*/
	public function AuthenticateUser( $username, $password )
	{
		require_once Settings::DBPath();
		$DB = new Database();
		
		$status = false;
		
		if ( $DB->Connect() )
		{	
			$statement = $DB->Prepare( "SELECT UserID, Username FROM users WHERE Username=? AND Password=?" );
			$statement->bind_param( "ss", $username, $password );
			$statement->execute();
			$statement->bind_result( $row_userID, $row_username );
			$statement->fetch();
			
			$status = ( $row_username == $username );
			$access->Login( $row_userID );
			
			$statement->close();
			$DB->Close();
        
		}
		
		return $status;
	}
}
